home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / ShapePart Browser ƒ / AutoMouse.c next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  2.4 KB  |  130 lines  |  [TEXT/KAHL]

  1. /*
  2.  *    AutoMouse.c
  3.  *
  4.  *    Robert Dierkes,  April 26, 1993
  5.  */
  6.  
  7. /*------------------*/
  8. /*    Include Files    */
  9. /*------------------*/
  10. #include "math routines.h"
  11. #include "graphics routines.h"
  12. #include "graphics toolbox.h"
  13.  
  14. #include "AutoMouse.h"
  15.  
  16.  
  17. /*----------------------*/
  18. /*    Global Declarations    */
  19. /*----------------------*/
  20. Boolean        gMoveMouse,
  21.             gFirstTime;
  22. fixed        gDegrees;
  23. long        gScale;
  24. Point        gPosition,
  25.             gLocalCenter,
  26.             gCenter;
  27.  
  28.  
  29. /*------------------------------*/
  30. /*    External Declarations     */
  31. /*------------------------------*/
  32.  
  33.  
  34. #define    MTemp        0x0828
  35. #define    RawMouse    0x082C
  36. #define    CrsrCouple    0x08CF
  37. #define    CrsrNew        0x08CE
  38.  
  39. #define    MTempL        (*((long *) MTemp))
  40. #define    RawMouseL    (*((long *) RawMouse))
  41.  
  42. #define    CrsrCoupleB    (*((char *) CrsrCouple))
  43. #define    CrsrNewB    (*((char *) CrsrNew))
  44.  
  45. #define    SetMousePosition(p)    {MTempL = RawMouseL = *((long *) p); CrsrNewB = CrsrCoupleB;}
  46.  
  47.  
  48. void InitializeAutoMouse (gxShape boundsShape)
  49. {
  50.     gxRectangle    bounds;
  51.  
  52.     gMoveMouse = false;
  53.     gFirstTime = true;
  54.     gDegrees   = 0;
  55.  
  56.     GXGetShapeBounds (boundsShape, 0, &bounds);
  57.  
  58.     /* Assumes the bounds are square */
  59.     gScale = FixedToInt (bounds.right - bounds.left) / 2;
  60.  
  61.     /* Get center of boundsShape */
  62.     gLocalCenter.h = gScale + FixedToInt (bounds.left);
  63.     gLocalCenter.v = gScale + FixedToInt (bounds.top);
  64.  
  65.     gScale -= 16;
  66. }
  67.  
  68.  
  69. boolean ToggleAutoMouse (void)
  70. {
  71.     /*    Is gPosition outside bounds of boxes?
  72.             Move mouse inside bounds
  73.     */
  74.  
  75.     if (gMoveMouse = ! gMoveMouse)
  76.     {
  77.         /* Adjust center point if window was moved */
  78.         gCenter  = gLocalCenter;
  79.         LocalToGlobal (&gCenter);
  80.  
  81.         gFirstTime = true;
  82.     }
  83.  
  84.     return (! gMoveMouse);
  85. }
  86.  
  87.  
  88. #undef    kShowMousePath
  89. #define    kDegreesAdvance    fixed1>>6
  90.  
  91. #define FractToFix(a)    ((fixed)(a) >> 14)
  92.  
  93. void MoveAutoMouse (void)
  94. {
  95.     fract    cosine,
  96.             sine;
  97.  
  98.     if (! gMoveMouse)
  99.         return;
  100.  
  101.     /* Stop the automated mouse if user the moved mouse */
  102.     if (gFirstTime)
  103.         gFirstTime = false;
  104.     else
  105.     {    if (RawMouseL != (*((long *) &gPosition)))
  106.         {
  107.             ToggleAutoMouse ();
  108.             return;
  109.         }
  110.     }
  111.  
  112.     /* Advance the mouse to a new position */
  113.     FractSineCosine (31 * gDegrees, &cosine);
  114.     sine = FractSineCosine (29 * gDegrees, nil);
  115.     gDegrees += kDegreesAdvance;
  116.  
  117.     gPosition.h = FixedToInt (FractToFix (cosine) * gScale) + gCenter.h;
  118.     gPosition.v = FixedToInt (FractToFix (sine)   * gScale) + gCenter.v;
  119.     SetMousePosition (&gPosition);
  120.  
  121. #ifdef    kShowMousePath
  122.     {    Point    curPosition;
  123.         curPosition = gPosition;
  124.         GlobalToLocal (&curPosition);
  125.         MoveTo (curPosition.h, curPosition.v);
  126.         Line (0, 0);
  127.     }
  128. #endif
  129. }
  130.